package com.yupi.springbootinit.juc;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @Description
 * @Author minify
 * @Date 2023/12/19 23:37
 * @Project mybi-backend
 */
public class RunAndRunAsync {

    public static void main(String[] args) {

        ExecutorService executorService = Executors.newFixedThreadPool(3);
        CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("任务1" + Thread.currentThread().getName());
            return "123";
        }, executorService).thenRunAsync(() -> {
            System.out.println("任务2" + Thread.currentThread().getName());
        }).thenRun(() -> {
            System.out.println("任务3" + Thread.currentThread().getName());
        }).whenComplete((s, e) -> {
            executorService.shutdown();
        });


    }
}
